package com.fescoservice.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.fescoservice.model.SeekerPersonalInfo;

/**
 * A data access object (DAO) providing persistence and search support for
 * SeekerPersonalInfo entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.fescoservice.dao.SeekerPersonalInfo
 * @author MyEclipse Persistence Tools
 */

public class SeekerPersonalInfoDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory
			.getLog(SeekerPersonalInfoDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String FAMILY_NAME = "familyName";
	public static final String SEXUAL = "sexual";
	public static final String NATIONALITY = "nationality";
	public static final String RESIDENCE = "residence";
	public static final String ADDRESS = "address";
	public static final String EMAIL = "email";
	public static final String HOME_NUM = "homeNum";
	public static final String WORK_NUM = "workNum";
	public static final String TEL_NUM = "telNum";
	public static final String MAIL_ADDR = "mailAddr";
	public static final String ZIPCODE = "zipcode";
	public static final String LANGUAGE = "language";

	protected void initDao() {
		// do nothing
	}

	public void save(SeekerPersonalInfo transientInstance) {
		log.debug("saving SeekerPersonalInfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(SeekerPersonalInfo persistentInstance) {
		log.debug("deleting SeekerPersonalInfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public SeekerPersonalInfo findById(java.lang.Long id) {
		log.debug("getting SeekerPersonalInfo instance with id: " + id);
		try {
			SeekerPersonalInfo instance = (SeekerPersonalInfo) getHibernateTemplate()
					.get("com.fescoservice.model.SeekerPersonalInfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(SeekerPersonalInfo instance) {
		log.debug("finding SeekerPersonalInfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding SeekerPersonalInfo instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from SeekerPersonalInfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByFamilyName(Object familyName) {
		return findByProperty(FAMILY_NAME, familyName);
	}

	public List findBySexual(Object sexual) {
		return findByProperty(SEXUAL, sexual);
	}

	public List findByNationality(Object nationality) {
		return findByProperty(NATIONALITY, nationality);
	}

	public List findByResidence(Object residence) {
		return findByProperty(RESIDENCE, residence);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findByHomeNum(Object homeNum) {
		return findByProperty(HOME_NUM, homeNum);
	}

	public List findByWorkNum(Object workNum) {
		return findByProperty(WORK_NUM, workNum);
	}

	public List findByTelNum(Object telNum) {
		return findByProperty(TEL_NUM, telNum);
	}

	public List findByMailAddr(Object mailAddr) {
		return findByProperty(MAIL_ADDR, mailAddr);
	}

	public List findByZipcode(Object zipcode) {
		return findByProperty(ZIPCODE, zipcode);
	}

	public List findByLanguage(Object language) {
		return findByProperty(LANGUAGE, language);
	}

	public List findAll() {
		log.debug("finding all SeekerPersonalInfo instances");
		try {
			String queryString = "from SeekerPersonalInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public SeekerPersonalInfo merge(SeekerPersonalInfo detachedInstance) {
		log.debug("merging SeekerPersonalInfo instance");
		try {
			SeekerPersonalInfo result = (SeekerPersonalInfo) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(SeekerPersonalInfo instance) {
		log.debug("attaching dirty SeekerPersonalInfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(SeekerPersonalInfo instance) {
		log.debug("attaching clean SeekerPersonalInfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static SeekerPersonalInfoDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (SeekerPersonalInfoDAO) ctx.getBean("SeekerPersonalInfoDAO");
	}
}